﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SQLite;

public partial class SaleInfo_AuditID : UDCPage
{
    private int _did = -1;
    protected int DID
    {
        get { return _did; }
        set { _did = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DID = String.IsNullOrEmpty(Request.QueryString["Did"])
                ? GetDid() : Int32.Parse(Request.QueryString["Did"].ToString());
            did.Text = DID.ToString();
            if (!String.IsNullOrEmpty(Request.QueryString["sid"]))
            {
                sid.Text = Request.QueryString["sid"].ToString();
                SaleBind(Int32.Parse(sid.Text));
            }
            if (!IsAuditor() || HaveAudited())
            {
                delete.Visible = false;
            }
        }
    }

    private void SaleBind(int sid)
    {
        string sqlstr = @"select serviceid,case iscontract when 1 then '是' else '否' end as iscontract
                                ,case isnew when 1 then '是' else '否' end as isnew
                                ,saledesc,dvname from ud_saleinfo_t t1 left join ud_developer_t t2 on t1.dvid = t2.dvid and t2.ifvalid = 1
                           where sid = $sid";
        SQLiteParameter[] spc = { 
                                    new SQLiteParameter("$sid",DbType.Int32)
                                };
        spc[0].Value = sid;
        DataRow dr = SQLiteHelper.ExecuteDataRow(sqlstr, spc);
        serviceId.Text = dr["serviceid"].ToString();
        IsContract.Text = dr["iscontract"].ToString();
        IsNew.Text = dr["isnew"].ToString();
        dvName.Text = dr["dvname"].ToString();
        SaleDesc.Value = dr["saledesc"].ToString();
    }
    protected void delete_Click(object sender, EventArgs e)
    {
        string sqlstr = "delete from ud_saleinfo_t where sid = $sid";
        SQLiteParameter[] spc = { 
                                    new SQLiteParameter("$sid",DbType.Int32)
                                };
        spc[0].Value = Int32.Parse(sid.Text);
        SQLiteHelper.ExecuteNonQuery(sqlstr, spc);
        Response.Redirect("AuditDetail.aspx?did="+did.Text);
    }
}